#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int sz = nums.size();
        vector<int> l(sz, 1), r(sz, 1);

        for (int i = 1; i < sz; i++)
        {
            l[i] = l[i - 1] * nums[i - 1];
        }

        for (int i = sz - 2; i >= 0; i--)
        {
            r[i] = r[i + 1] * nums[i + 1];
        }

        vector<int> temp(sz);
        for (int i = 0; i < sz; i++)
        {
            temp[i] = l[i] * r[i];
        }
        return temp;
    }
};